package com.zsj.comminlibrary.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zsj.comminlibrary.R;

import androidx.annotation.NonNull;


public class LoadingDialog extends Dialog {

    private Context mContext;
    private Builder mBuilder;

    public LoadingDialog(@NonNull Context context) {
        super(context);
        mContext = context;
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }

    public void setBuilder(Builder builder) {
        mBuilder = builder;
    }

    private void setTitle(String titile) {
        mBuilder.setLoading(titile);
    }

    public static class Builder{
        private TextView mTvTitle;
        private LoadingDialog mDialog;
        private Context mContext;


        public Builder(Context context) {
            mContext = context;
            mDialog = new LoadingDialog(mContext, R.style.Dialog);
            mDialog.setBuilder(this);
            View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_loading, null);
            mTvTitle = view.findViewById(R.id.tv_loading);

            mDialog.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        public Builder setLoading(String title) {
            mTvTitle.setText(title);
            return this;
        }


        public LoadingDialog build() {
            mDialog.setCancelable(true);
            return mDialog;
        }

    }



}
